package com.hu.gulimallproduct.project.service.impl;


import com.hu.gulimallcommon.utils.Query;
import com.hu.gulimallproduct.project.dao.PmsBrandDao;
import com.hu.gulimallproduct.project.entity.PmsBrandEntity;
import com.hu.gulimallproduct.project.service.PmsBrandService;
import com.hu.gulimallproduct.project.service.PmsCategoryBrandRelationService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hu.gulimallcommon.utils.PageUtils;



@Service()
public class PmsBrandServiceImpl extends ServiceImpl<PmsBrandDao, PmsBrandEntity> implements PmsBrandService {
    @Autowired
    private PmsCategoryBrandRelationService brandRelationService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String)params.get("key");
        QueryWrapper<PmsBrandEntity> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(key)){
            queryWrapper.eq("brand_id",key).or().like("name",key);
        }
        IPage<PmsBrandEntity> page = this.page(
                new Query<PmsBrandEntity>().getPage(params),queryWrapper
        );
        return new PageUtils(page);
    }

    @Override
    public void updateDetail(PmsBrandEntity pmsBrand) {
        this.updateById(pmsBrand);
        if(!StringUtils.isEmpty(pmsBrand.getName())){
            //更新其他关联表中的数据
            brandRelationService.updateBrand(pmsBrand.getBrandId(),pmsBrand.getName());
        }
    }

}